<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/tags/trymore" prefix="tm"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>

<style>
	.grid .gridTbody td.noborder {border-bottom: none;}
	.grid .gridTbody table.logcont td {line-height: 30px; padding: 0 5px; text-align: left;}
	.logtext {word-wrap:break-word; word-break:break-all; text-align:left;}
	.logtext div {overflow:auto; word-wrap: break-word;  text-align:left;}
</style>

<script>
	function forwardToWeek (ele_id) {
		navTab.reload("app/worklog.do?action=pageWorkLogIndex&cat=${cat}&date=" + $("#"+ele_id).val());
	}
</script>

<div id="logwrapper_${cat}">
	
	<!-- 周信息 -->
	<div class="panelBar" style="border-bottom:none; border-top:none;">
		<div style="float:left;">
			<h2 style="line-height:23px; padding: 0 0 0 5px;">
				一周工作日志  
				[
					<span style="color:#CF0800">
						<fmt:formatDate value="${startDate}" type="date" pattern="yyyy-MM-dd"/> 
						~
						<fmt:formatDate value="${endDate}" type="date" pattern="yyyy-MM-dd"/>
						(${weekParam}周)
					</span>
				]
			</h2>
		</div>
		<ul class="toolBar" style="float:right">
			<c:if test="${weekParam - 1 > 0}">
				<li>
					<a class="previous" href="app/worklog.do?action=pageWorkLogIndex&cat=${cat}&week=${weekParam - 1}" 
						target="ajax" rel="logwrapper_${cat}" title="查看上一周工作日志" mask="true" width="504" height="240">
						<span>上一周</span>
					</a>
				</li>
			</c:if>
			<li>
				<a class="icon" href="app/worklog.do?action=pageWorkLogIndex&cat=${cat}&week=${weekNum}" 
					target="ajax" rel="logwrapper_${cat}" title="查看本周工作日志" mask="true" width="504" height="240">
					<span>当前周</span>
				</a>
			</li>
			<c:if test="${weekParam + 1 <= maxWeekNum}">
				<li>
					<a class="next" href="app/worklog.do?action=pageWorkLogIndex&cat=${cat}&week=${weekParam+1}" 
						target="ajax" rel="logwrapper_${cat}" title="查看下一周工作日志" mask="true" width="504" height="240">
						<span>下一周</span>
					</a>
				</li>
			</c:if>
		</ul>
	</div>
	
	<!-- 周跳转 -->
	<div class="panelBar" style="height:30px;">
		<div class="searchBar" style="overflow:hidden;">
			<table style="float:left" class="searchContent" id="record_form">
				<tr>
					<td style="padding-right:10px;">
						<label style="line-height:30px;width:100px">跳转至日期所在周：</label>
						<input class="textInput date" value="<fmt:formatDate value="${currentDate}" type="date" pattern="yyyy-MM-dd"/>" id="worklogStartDate_${cat}" name="worklogStartDate" type="text" style="margin-top:5px;"/>
					</td>
					<td><a class="button" onclick="javascript:forwardToWeek('worklogStartDate_${cat}')"><span>跳转</span></a></td>
				</tr>
			</table>
			<ul class="toolBar" style="float:right;position:relative; top: 3px; right: 3px;">
				<li>
					<a class="add" target="dialog" title="工作日志查询" 
						href="app/worklog.do?action=dialogWorkLogQuery&cat=${cat}&mode=query" width="820" height="570"><span>日志查询</span></a>
				</li>
			</ul>
		</div>
	</div>
	
	<!-- Body -->	
	<div class="pageContent">
		<div id="datagrid">
			<table class="table" width="100%" layoutH="80">
				<thead>
					<tr>
						<th align="center" width="80px">日期</th>
						<th align="center" width="30px">序号</th>
						<th align="center" width="85px">项目编号</th>
						<th align="center">项目名称</th>
						<th align="center" width="120px">工作类别</th>
						<th align="center">工作事件</th>
						<c:if test="${cat eq 'personal' or (cat eq 'department' && tm:inRange('ROLE_SUPER,ROLE_PROJECT_ASSISTANT', sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.roleKey, ','))}">
						<th align="center" width="100px">日志管理</th>
						</c:if>
					</tr>
				</thead>
				<tbody>
					<logic:present name="wholeDates">
						<logic:iterate name="wholeDates" id="date" indexId="idx">
							<tr id="workdate-${idx}" ${idx % 2 == 1 ? 'style="background-color: #F5F5F5"' : ''}>
								<td rowspan="${fn:length(logData[date]) gt 0 ? fn:length(logData[date]) : 1}" style="${nowDate eq date ? 'font-weight:bold;color:#B60000' : ''}">${date}</td>
								<c:choose>
									<c:when test="${fn:length(logData[date]) gt 0}">
										<c:forEach items="${logData[date]}" var="item" varStatus="status" end="0">
											<td>${status.index+1}</td>
											<td>${item.logProject ne null ? item.logProject.projectNo : 'N/A'}</td>
											<td class="logtext">${item.logProject ne null ? item.logProject.projectName : '非工作项目'}</td>
											<td>${item.logWorkType.dictKey}</td>
											<td class="logtext">${item.logEvent}</td>
										</c:forEach>
									</c:when>
									<c:otherwise>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
									</c:otherwise>
								</c:choose>
								<c:if test="${cat eq 'personal' or (cat eq 'department' && tm:inRange('ROLE_SUPER,ROLE_PROJECT_ASSISTANT', sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.roleKey, ','))}">
									<td rowspan="${fn:length(logData[date]) gt 0 ? fn:length(logData[date]) : 1}">
										<a href="app/worklog.do?action=dialogWorkDailyLogMaintenance&cat=${cat}&date=${date}" 
											class="oplink" target="dialog" title="日志内容维护 : ${date}" width="820" height="450" rel="">日志维护</a>
									</td>
								</c:if>
							</tr>
							
							<c:forEach items="${logData[date]}" var="item" varStatus="status" begin="1">
								<tr id="workdate-${idx}-${status.index}">
									<td>${status.index+1}</td>
									<td>${item.logProject.projectNo}</td>
									<td class="logtext">${item.logProject ne null ? item.logProject.projectName : '非工作项目'}</td>
									<td>${item.logWorkType.dictKey}</td>
									<td class="logtext">${item.logEvent}</td>
								</tr>
							</c:forEach>
						</logic:iterate>
					</logic:present>
					<tr style="background-color: #FFFFB8">
						<td>一周工作总结</td>
						<td colspan="5" style="text-align:left;padding-left: 5px;line-height:25px">
							<logic:present name="weekLog">
								${weekLog.logEvent}
							</logic:present>
						</td>
						<c:if test="${cat eq 'personal' or (cat eq 'department' && tm:inRange('ROLE_SUPER,ROLE_PROJECT_ASSISTANT', sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.roleKey, ','))}">
							<td>
								<a href="app/worklog.do?action=dialogWorkWeeklyLogMaintenance&cat=${cat}&startDate=<fmt:formatDate value='${startDate}' type='date' pattern='yyyy-MM-dd'/>&endDate=<fmt:formatDate value='${endDate}' type="date" pattern="yyyy-MM-dd"/>&currentDate=<fmt:formatDate value='${currentDate}' type='date' pattern='yyyy-MM-dd'/>" 
									class="oplink" target="dialog" title="一周工作总结维护 : <fmt:formatDate value='${startDate}' type='date' pattern='yyyy-MM-dd'/> - <fmt:formatDate value='${endDate}' type='date' pattern='yyyy-MM-dd'/>" width="590" height="240" rel="">日志维护</a>
							</td>
						</c:if>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>